package com.concurrent.syncContainer;

import com.concurrent.annotations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.Vector;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/**
 * @author: zhouyang
 * @descrpition: vector容器 一般情况下是线程安全的 但是要修改会越界
 * @time: 2019-05-07 13:38
 */
@Slf4j
@ThreadSafe
public class Vector2 {
    private static Vector<Integer> vector = new Vector<>();

    public static void main(String[] args) throws Exception{
        for (int i = 0; i < 10; ++i) vector.add(i);
        Thread thread1 = new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < vector.size(); ++i) vector.remove(i);
            }
        };

        Thread thread2 = new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < vector.size(); ++i) vector.get(i);
            }
        };
        thread1.start();
        thread2.start();
        Thread.sleep(2000);
    }
}
